<template>
  <div class="WorkingSchedule" v-loading="loading">
    <el-form ref="form" :model="form" label-position="top" class="myform">
      <div>
        <el-form-item label="款号" class="myform-item">
          <el-input
            v-model="form.type_no"
            placeholder="请输入款号"
            clearable
            @keyup.enter.native="onSearch"
          ></el-input>
        </el-form-item>
        <el-form-item label="品名" class="myform-item">
          <el-input
            v-model="form.type_name"
            placeholder="请输入品名"
            clearable
            @keyup.enter.native="onSearch"
          ></el-input>
        </el-form-item>
        <el-form-item label="版师" class="myform-item">
          <el-input
            v-model="form.publisher"
            placeholder="请输入版师"
            clearable
            @keyup.enter.native="onSearch"
          ></el-input>
        </el-form-item>
        <el-form-item style="margin-top: 50px">
          <el-button type="primary" @click="onSearch">查询</el-button>
        </el-form-item>
      </div>
      <div>
        <!-- <el-form-item style="margin-top: 50px">
          <el-button
            type="primary"
            @click="onEdit()"
            icon="el-icon-plus"
            >新建</el-button
          >
        </el-form-item> -->
      </div>
    </el-form>
    <el-table :data="tableData" style="width: 100%" border>
      <el-table-column label="商品基本信息" align="center" prop="type_no">
        <template slot-scope="{ row }">
          <div class="goods">
            <el-image lazy class="goods-img" :src="row.image[0]" fit="contain" :preview-src-list="row.image" lazy></el-image>
            <div class="goods-div">
              <div>品名：{{row.type_name}}</div>
              <div>{{row.type_no}}</div>
            </div>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        label="最后修改时间"
        align="center"
        prop="chanping_up_time"
      ></el-table-column>
      <el-table-column
        label="版师"
        align="center"
        prop="publisher"
      ></el-table-column>
      <el-table-column label="操作" align="center" fixed="right">
        <template slot-scope="{ row }">
          <el-button v-if="qxobj.save" type="text" @click="onEdit(row.type_no)">编辑</el-button>
          <el-button type="text" @click="onLook(row.type_no)">查看</el-button>
          <!-- <el-button type="text" @click="onEdit(row.id)">下载</el-button> -->
          <el-button
            type="text"
            style="color: red"
            v-if="row.size_code_status == 1 && qxobj.save"
            @click="onIs(row.type_no, 0)"
            >解锁</el-button
          >
          <el-button
            type="text"
            style="color: #67c23a"
            v-if="row.size_code_status == 0 && qxobj.save"
            @click="onIs(row.type_no, 1)"
            >锁定</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      :form="form"
      :total="total"
      @paginationPostOrderTaskList="postAdminOperateGetProductsSize"
    />
  </div>
</template>

<script>
import {
  postAdminOperateGetProductsSize,
  postAdminOperateDelOrtherProduct,
  postAdminOperateSetlocking,
} from "@/api";
import pagination from "@/components/pagination.vue";
export default {
  components: { pagination },
  data() {
    return {
      loading: false,
      dialogVisible: false, //审核
      qxobj:"",
      form: {
        type_no: "",
        type_name: "",
        publisher: "",
        page: 1,
        size: 10,
      },
      tableData: [],
      total: 1,
    };
  },
  activated() {
    this.qxobj = JSON.parse(this.$route.query.qxobj);
    let form = this.form;
    this.postAdminOperateGetProductsSize(form);
  },
  methods: {
    handleClose() {},
    onLook(type_no) {
      if (!type_no) {
        this.$router.push({
          name: "processSizepdf",
        });
      } else {
        this.$router.push({
          name: "processSizepdf",
          query: { type_no },
        });
      }
    },
    // 查看
    onEdit(type_no) {
      if (!type_no) {
        this.$router.push({
          name: "ProcessMaintenanceSizeEdit",
        });
      } else {
        this.$router.push({
          name: "ProcessMaintenanceSizeEdit",
          query: { type_no },
        });
      }
    },
    async onIs(type_no, status) {
      let obj = {
        type_no: type_no,
        type:1,
        status: status,
      };
      this.$confirm(`确定${status == 0 ? "解锁" : "锁定"}`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(async () => {
          await postAdminOperateSetlocking(obj);
          let form = this.form;
          this.postAdminOperateGetProductsSize(form);
        })
        .catch(() => {});
    },
    // 删除
    onDelete(id) {
      let obj = {
        id,
      };
      let { form } = this;
      this.$confirm("确定删除该标签种类?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          postAdminOperateDelOrtherProduct(obj).then((res) => {
            this.postAdminOperateGetProductsSize(form);
            this.$message({
              type: "success",
              message: "删除成功!",
            });
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },

    // 采购列表
    async postAdminOperateGetProductsSize(data) {
      this.loading = true;
      this.form = data;
      postAdminOperateGetProductsSize(data)
        .then((res) => {
          this.loading = false;
          console.log("采购列表", res);
          this.tableData = res.data;
          this.total = Number(res.total);
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    // 搜索
    onSearch() {
      this.form.page = 1;
      this.form.size = 10;
      this.postAdminOperateGetProductsSize(this.form);
    },
  },
};
</script>

<style lang="scss" scoped>
.myform {
  display: flex;
  justify-content: space-between;
  > div {
    display: flex;
  }
  &-item {
    margin-right: 10px;
  }
}
.WorkingSchedule {
  background: #ffff;
  padding: 20px;
  border-radius: 2px;
  @include boxShadow;
}
.goods{
  display: flex;
  align-items: center;
  justify-content: center;
  .goods-img{
    width: 60px;
    height: 60px;
    margin-right: 10px;
  }
  .goods-div{
    width: 300px;
    >div:nth-child(2){
      color:#999
    }
  }
}
</style>
